<template>
  <div class='container'>
    <div title="添加文章">
      <el-form :model="addForm"
               :rules="addFormRules"
               ref="addFormRef"
               label-width="100px">
        <el-form-item label="文章标题"
                      prop="title">
          <el-input v-model="addForm.title"
                    placeholder="请输入文章标题"></el-input>
        </el-form-item>
        <el-form-item label="文章内容"
                      prop="articleBody">
          <quill-editor v-model="addForm.articleBody"></quill-editor>
        </el-form-item>
        <el-form-item label="视频地址"
                      prop="videoURL">
          <el-input v-model="addForm.videoURL"
                    placeholder="请输入视频地址"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer">
        <el-button @click="$emit('close')">取消</el-button>
        <el-button type="primary"
                   @click="addArticle">确认</el-button>
      </span>
    </div>
  </div>
</template>

<script>
import { add } from '@/api/hmmm/articles'
export default {
  name: 'ArticlesAdd',
  components: {},
  props: {},
  data() {
    return {
      addForm: {
        title: '',
        articleBody: '',
        videoURL: ''
      },
      addVisible: false,
      addFormRules: {
        title: [
          { required: true, message: '请输入文章标题', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        articleBody: [
          { required: true, message: '请输入文章内容', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' }
        ],
        videoURL: [
          { required: true, message: '请输入视频地址', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 添加文章
    addArticle() {
      this.$refs.addFormRef.validate((valid) => {
        if (!valid) return

        add(this.addForm).then(() => {
          this.$message.success('添加文章成功')
          this.$emit('addAstr')

          // 关闭弹层
          this.$emit('close')
        })
      })
    }
  }
}
</script>

<style scoped lang='less'></style>
